<?php

GaAPI_Autoloader::instance()->load('GaAPI_Objects_Common_Object');

class GaAPI_Objects_AdGroup_Ad extends GaAPI_Objects_Common_Object {

    public $adGroupId;
    public $ad;
    protected $_status;
    public $stats;


    public function  __construct() {
        GaAPI_Autoloader::instance()->load('GaAPI_Objects_AdGroup_Ad_Status');
        $this->_status = new GaAPI_Objects_AdGroup_Ad_Status();
    }

    public function  __set($name,  $value) {
        if ($name == 'status') {
            $this->_status->set($value);
        }
        return $this->$name = $value;
    }


    public function &__get($name) {
        if ($name == 'status') {
            return $this->_status;
        }
    }


    public function setAdType($type) {
        $className = 'GaAPI_Objects_Ad_' . $type;
        GaAPI_Autoloader::instance()->load($className);
        $this->ad = new $className;
    }

    public function  __toString() {
        $xml = '';
        $xml .= '<adGroupId>' . $this->adGroupId . '</adGroupId>';
        $xml .= '<ad xsi:type="' . $this->ad->type . '">' . $this->ad . '</ad>';
        $xml .= '<status>' . $this->status . '</status>';
        return $xml;
    }

}